package com.lixin.smartclassroom.ui.home.tab5.activity

import android.view.LayoutInflater
import android.view.ViewGroup
import com.drake.brv.utils.bindingAdapter
import com.drake.net.utils.scopeNetLife
import com.lixin.smartclassroom.R
import com.lixin.smartclassroom.api.classhistorylist
import com.lixin.smartclassroom.api.classstudent
import com.lixin.smartclassroom.api.classteacher
import com.lixin.smartclassroom.api.courselist
import com.lixin.smartclassroom.api.jingcaishikelist
import com.lixin.smartclassroom.bean.DataListBean
import com.lixin.smartclassroom.databinding.FragmentRecyclerCustomBinding
import com.lixin.smartclassroom.ui.home.adapter.classStudent
import com.lixin.smartclassroom.ui.home.adapter.classTeacher
import com.lixinkeji.base.BaseActivity
import com.lixinkeji.base.BaseFragment
import com.lixinkeji.extension.getIntentInt
import com.lixinkeji.extension.getIntentString
import com.lixinkeji.extension.gone
import com.lixinkeji.extension.start
import com.lixinkeji.extension.visible

/**
 * Description 班级学生
 * Author: lwc
 * Date:2023/12/9 15:42
 */
class ClassStudentAct : BaseActivity<FragmentRecyclerCustomBinding>() {

    private var listBeans = ArrayList<DataListBean>()
    private var classid = ""
    private var type = 1
    private var listBean = ArrayList<DataListBean>()

    override fun title(): String {
        type = getIntentInt("type")
        when (type) {
            1 -> return "班级学生"
            2 -> return "班级老师"
        }
        return super.title()
    }

    private fun getData() {
        classid = getIntentString("classid")

        when (type) {
            1 -> binding.recycler.classStudent().apply {
                R.id.rl.onClick {
                    start(ClassStudentPaperAct::class.java) {
                        putExtra("classid", classid)
                        putExtra("studentid", getModel<DataListBean>(modelPosition).id)
                    }
                }
            }

            2 -> binding.recycler.classTeacher()
        }

        scopeNetLife {
            binding.apply {
                refresh.onRefresh {
                    scopeNetLife {
                        listBean = classstudent(index, 10, classid, type.toString())!!

                        addData(listBean) {
                            if (binding.recycler.bindingAdapter.models?.size == 0) {
                                binding.state.showEmpty()
                                binding.recycler.gone()
                            } else {
                                binding.recycler.visible()
                            }
                            listBean.size == 10
                        }
                    }
                }.autoRefresh()
            }
        }
    }

    override fun iniView() {
        getData()
    }

    override fun getViewBinding() = FragmentRecyclerCustomBinding.inflate(layoutInflater)

    override fun onClick() {

    }

}